﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Interfaces;

namespace TestApplication
{
    public class TestApplication : IApplication
    {
        public TestApplication()
		{
            mainInterface = new ctlMain(this);
            // Add constructor logic here
		}
		
		//Declarations of all our internal plugin variables
		IMiddleware host = null;
		ctlMain mainInterface;

        /// <summary>
        /// Name of the plugin.
        /// </summary>
        public string Name
        {
            get { return "Test"; }
        }

		/// <summary>
		/// Description of the Plugin's purpose
		/// </summary>
		public string Description
		{
            get { return "Testing purpose"; }
		}

		/// <summary>
		/// Author of the plugin
		/// </summary>
		public string Author
		{
            get { return "pazsoo"; }
        }

        public string Version
        {
            get { return "1.01"; }
        }

		/// <summary>
		/// Host of the plugin.
		/// </summary>
		public IMiddleware Host
		{
            get { return host; }
            set { host = value; }
		}

		public System.Windows.Forms.UserControl MainInterface
		{
            get { return mainInterface; }
		}

        public int myProtoId;
        public int myTestMarkerId = -1; 
		
		public void Initialize()
		{
            System.IO.Stream bgImage = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("TestApplication.Resources.red_marker.png");

            myProtoId = host.CreateTemplate(bgImage, new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), this.GetHashCode().ToString());

            host.NewCellDataAvailable += new NewCellDataAvailableHandler(host_NewCellDataAvailable);
            host.NewWifiDataAvailable += new NewWifiDataAvailableHandler(host_NewWifiDataAvailable);
            host.NewAbsoluteDataAvailable += new NewAbsoluteDataAvailableHandler(host_NewAbsoluteDataAvailable);
            host.NewPairedDataAvailable += new NewPairedDataAvailableHandler(host_NewPairedDataAvailable);

            host.InitSettingsGroup(this.Name);
		}

        void host_NewWifiDataAvailable(object sender, WifiData[] data)
        {
            mainInterface.UpdateWifiFields(data);
        }

        void host_NewPairedDataAvailable(object sender, IAbsoluteData absoluteData, IProximityData proximityData)
        {
            mainInterface.AddDataPair(absoluteData, proximityData.HashValue);
          //  host.NewMarker(absoluteData.Latitude, absoluteData.Longitude);
        }

        void host_NewAbsoluteDataAvailable(object sender, IAbsoluteData data)
        {
            mainInterface.UpdateGpsFields(data.Time, data.Latitude, data.Longitude);
        }

        void host_NewCellDataAvailable(object sender, CellData data)
        {
            mainInterface.UpdateCellFields("MCC: " + data.Mcc + " MNC: " + data.Mnc + " Id: " + data.Id);

            host.SetSetting(this.Name, "LastCell", data.Id);
        }
		
		public void Dispose()
		{
			//Put any cleanup code in here for when the program is stopped
		}

        #region IModule Members

        CustomControls.AlphaImage IModule.IconEnabled
        {
            get { return CustomControls.AlphaImage.CreateFromResource("TestApplication.Resources.icon_enabled.png"); }
        }

        CustomControls.AlphaImage IModule.IconDisabled
        {
            get { return CustomControls.AlphaImage.CreateFromResource("TestApplication.Resources.icon_disabled.png"); }
        }

        public bool Sleep()
        {
            throw new NotImplementedException();
        }

        public bool Wake()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
